<template>
    <div class="funds-wrap">
        <van-nav-bar title="资金明细" left-text="返回" left-arrow @click-left="$router.go(-1)" />
        <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="getData">
            <van-cell-group>
              <van-cell v-for="(item,index) in data" :key="index" :label="`${item.order_sn}  赠送积分${item.integral}`">
              <div slot="title">
                <template v-if="item.pay_mode == 'Wechat'">
                  微信支付
                </template>
                <template v-else>
                  其他支付方式
                </template>
              </div>
              <div slot="default">
              <template v-if="item.money >= 0">
                <span style="color: green">{{ item.money }} </span>
              </template>
              <template v-else>
                <span style="color: red"> {{ item.money }} </span>
              </template>
              </div>
              </van-cell>
            </van-cell-group>
        </van-list>
    
    </div>
</template>

<script>
export default {
    name: 'funds',
    props: ['id'],
    data() {
        return {
            data: [],
            c_page: null,
            loading: true,
            finished: false,

        }
    },
    created() {
        this.getData()
    },
    methods: {
        async getData(id = this.id) {
            const res = await this.axios.post(`/api/store/admin/record/transaction/${id}/StoreExpense`, {
                page: this.c_page + 1 || 1
            });
            this.c_page = res.data.data.current_page;

            if (res.data.data.current_page == 1) {
                this.data = res.data.data.data;
            } else {
                this.data = [...this.data, res.data.data.data]
            }
            if (this.c_page >= res.data.data.last_page) {
                this.finished = true;
                this.loading = false;
            }
        }
    }
}
</script>

<style lang="scss" scoped>

</style>
